<?php
require_once ("../dao/DealerDAO.php");
$action = $_POST['act'];
if($action == 'acti') {
	$result = false;
	if(isset($_POST['idre'])) {
		$id = $_POST['idre'];
		$code = "DL";
		$arridcode = getidlastdealer();
		if(count($arridcode) > 0) {
			$lastcode = $arridcode[0][0];
			$lastcode = substr($lastcode, 2, strlen($lastcode));
			$lastcode += 1;
			
			$temp = "";
			$lengcode = strlen($lastcode);
			if($lengcode < 4) {
				for($i = 0; $i < 4-$lengcode; $i++) {
					$temp .= "0";
				}
			}
			$code .= $temp.$lastcode;
		} else {
			$code .= "0001";
		}
		
		
		if(updateActivityDealer($id, $code)) {
			$result = true;
		}
	}
	echo json_encode($result);
} else if($action == 'lockacc') {
	$result = false;
	if(isset($_POST['idre'])) {
		$id = $_POST['idre'];
		if(updateLockDealer($id)) {
			$result = true;
		}
	}
	echo json_encode($result);
} else if($action == 'unlockacc') {
	$result = false;
	if(isset($_POST['idre'])) {
		$id = $_POST['idre'];
		if(updateUnlockDealer($id)) {
			$result = true;
		}
	}
	echo json_encode($result);
}

?>